<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
		<title>订单查询</title>
		<jsp:include page="/page/jsp/member/head.jsp" />
		<script type="text/javascript">
			
			//删除
			function deleteSGRs(id){
				if(id!=""){
					$.ajax({
						   url: path+"/member/deleteSGRs.htm?id="+id,
						   success: function(data){
							   if(data=="0"){
								   window.location = path+"/member/presented.htm";   //成功跳回查看页面
							   }else{
								   alertBox("操作失败!");
							   }
						   }
					});
					
				}
			}
			
			function pageNext() {
				$('#pageNo').attr('value',${pagination.pageNum+1});
				$('#form1').submit();
			}
			
			function pagePre() {
				$('#pageNo').attr('value',${pagination.pageNum-1});
				$('#form1').submit();
			}
			
			function pageSelect() {
				$('#form1').submit();
			}
			
			/* 订单详情 */
			function orderDetail(id){
				if(id!=null){
					window.location = path+"/cart/continueOrder.htm?orderId="+id;   //跳转到订单确认页面，重新加载这个订单
				}
			}
			
			/* 确认收货 */
			function confirmProduct(id){
				if(id!=null){
					$.ajax({
						   url: path+"/member/confirmProduct.htm?orderId="+id,
						   success: function(data){
							   if(data=="0"){
								   window.location = path+"/member/myOrderURL.htm";   //成功跳回查看页面
							   }else if(data=='2'){
								   alertBox("未找到该订单!");
							   }else{
								   alertBox("操作失败!");
							   }
						   }
					});
				}
			}
			

			/* 删除 ,只有在订单被确定后才有删除权限 */
			function deleteOrder(id){
				var submit = function (v, h, f) {
					if(v == 'ok'){
						if(id!=null){
							$.ajax({
								   url: path+"/member/deleteOrder.htm?orderId="+id,
								   success: function(data){
									   if(data=="0"){
										   window.location = path+"/member/myOrderURL.htm";   //成功跳回查看页面
									   }else if(data=='2'){
										   alertBox("未找到该订单!");
									   }else{
										   alertBox("操作失败!");
									   }
								   }
							});
						}
					}
					
					return true;
				};
				$.jBox.confirm("确定要删除吗？", "提示", submit)
			}
			
			/* 申请退货跳转 */
			function returnProduct(orderNo){
				var submit = function (v, h, f) {
					if(v == 'ok'){
						if(orderNo!=null){
							window.location = path+"/member/returnProductURL.htm?orderNo="+orderNo;   //跳转到退货处理页面
						}
					}
				};
				$.jBox.confirm("确定要退货吗？", "提示", submit)
			}
			
			
			/*  取消退货申请    */
 			function cancelProduct(id){
				if(id!=null){
					$.ajax({
						   url: path+"/member/cancelProduct.htm?orderId="+id,
						   success: function(data){
							   if(data=="0"){
								   window.location = path+"/member/myOrderURL.htm";   //成功跳回查看页面
							   }else if(data=='2'){
								   alertBox("未找到该订单!");
							   }else{
								   alertBox("操作失败!");
							   }
						   }
					});
				}
			} 
			
			
			/*  查看订单商品页面跳转  */
			function findOrderProduct(id){
				if(id!=null){
					window.location = path+"/member/findOrderProduct.htm?orderId="+id;   
				}
			}
			
		</script>
	</head>
<body>
	<div class="right">
	<h1><b>我的订单</b></h1>
		<div class="ri_main">
			 <form id="form1" name="form1" action="<%=basePath %>member/myOrderURL.htm" method="post">
			  <table width="100%" id="mgrTable" border="0" cellpadding="8" cellspacing="1" class="margintop10" style="background:#d9d9d9;">
			    <tr>
			      <td width="6%" bgcolor="#eeeeee"><b>序号</b></td>
			      <td width="10%" bgcolor="#eeeeee"><b>订单编号</b></td>
			      <td width="6%" bgcolor="#eeeeee"><b>金额</b></td>
			      <td width="8%" bgcolor="#eeeeee"><b>运费</b></td>
			      <td width="30%" bgcolor="#eeeeee"><b>货品清单</b></td>
			      <td width="10%" bgcolor="#eeeeee"><b>状态</b></td>
			      <td width="30%" bgcolor="#eeeeee"><b>操作</b></td>
			    </tr>
			    <c:forEach var="list" items="${pagination.rows}" varStatus="s">
				  <tr>
				      <td bgcolor="#FFFFFF"><c:out value="${s.count}" /></td>
				      <td bgcolor="#FFFFFF">${list.orderNo}</td>
				      <td bgcolor="#FFFFFF">${list.score}</td>
				      <td bgcolor="#FFFFFF">${list.fare}</td>
				      <td bgcolor="#FFFFFF"><a href="javascript:void(0);" onclick="orderDetail(${list.id})">订单详情</a></td>
				      <td bgcolor="#FFFFFF">${list.selectStatus()}</td>
				      <td bgcolor="#FFFFFF">
			        	<c:if test="${list.status==1&&list.fareway=='1'&&list.payTime==null}"><!-- 还没有支付，可以继续支付或者是取消这个订单 -->
			        		<a href="<%=basePath %>alipay/${list.id}.htm" target="_blank">继续支付</a>
			        	</c:if>
			        	<c:if test="${list.status==3}"><!-- 还没有支付，可以继续支付或者是取消这个订单 -->
			        		<a href="<%=basePath %>alipay/${list.id}.htm" target="_blank">确认收货</a>
			        	</c:if>
				        <c:if test="${list.status==4}"><!-- 收货确认时间非空，则用户已经收到货，则可以执行删除或者退货申请 -->
				        	<a href="javascript:void(0);" onclick="deleteOrder(${list.id})">删除</a>
				        	<a href="javascript:void(0);" onclick="returnProduct(${list.orderNo})">申请退货</a>
				        </c:if>
				        <c:if test="${list.status==7}"><!-- 取消退货申请，因为如果要申请退货，必须先确认订单，取消退货申请则把状态再次改为4 -->
			        		<a href="javascript:void(0);" onclick="cancelProduct(${list.id})">取消退货申请</a>
			        	</c:if>
				      </td>
				  </tr>
			    </c:forEach>
			    </table>
			    
			    <c:if test="${ pagination.totalPage != 0}">
					<div class="page-nav">
						<c:choose>
							<c:when test="${pagination.pageNum==1 }">
								<span class="start">上一页</span>
							</c:when>
							<c:otherwise>
								<a href="javascript:pagePre();" class="prev">上一页</a>
							</c:otherwise>
						</c:choose>
						
						<span class="page-info">转到
							<select id="pageNo" name="pageNo" onchange="pageSelect()">
								<c:forEach var="p" begin="1" end="${pagination.totalPage }" step="1"> 
										<option <c:if test="${p==pagination.pageNum }">selected="selected"</c:if> value="${p }">${p }</option>
								</c:forEach> 
							</select>
							/${pagination.totalPage }页
						</span>
						
						<c:choose>
							<c:when test="${pagination.pageNum == pagination.totalPage }">
								<span class="last">下一页</span>
							</c:when>
							<c:otherwise>
								<a href="javascript:pageNext();" class="next">下一页</a>
							</c:otherwise>
						</c:choose>
					</div>
				</c:if>
			 </form>
		</div>
	</div>
</body>
</html>